package org.imlinker.plugin;

import javax.swing.Icon;
import javax.swing.ImageIcon;

import org.imlinker.list.ListItem;
import org.imlinker.util.Images;

public class PluginItem extends ListItem {

	public PluginItem(final Icon icon, final String title, final String name) {
		super(icon, title, name);
	}

	public PluginItem(final ImageIcon icon, final String title,
			final Class<?> paraClass) {
		this(icon != null ? icon : Images.getLogo16px(), title,
				"org.imlinker.plugin." + title);

		pluginClass = paraClass;
	}

	public void openPlugin() {
		if (plugin == null) {
			try {
				plugin = (Plugin) pluginClass.newInstance();
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}

		plugin.open();
	}

	private Plugin plugin = null;
	private Class<?> pluginClass;
}
